/** 表格 v1.0.0 **/
var cdMap = new Map();
// 用户 user_nickName
cdMap.set("senderId", "user_nickName");
cdMap.set("updateBy", "user_nickName");
cdMap.set("createBy", "user_nickName");
// kaOptionButtons
var kaOptionButtonMaps = new Map();
var kaOptionTopMenuButtonMaps = new Map();
var treegrid = {
    deConfig: { //默认参数
        elem: "", //对应绑定元素ID
        width: "100%", //宽度
        height: "100%", //高度
        fv: [], // 初始查询字段
        fsv: [], // 初始排序字段
        column: [], //字段
    },
    rc: function (config, str) {//判断返回值
        return config[str] == undefined || config[str] == null || config[str] == "" ? treegrid.deConfig[str] : config[str];
    },
    setFV: function (config, arrayList) { //设置查询
        if (config.fv != undefined && config.fv != null && config.fv != "" && config.fv.length > 0) {
            for (var i in config.fv) {
                arrayList.push(config.fv[i]);
            }
        }
        var oldArrayList = ka_grid_findValue.get(config.id);
        if (oldArrayList != undefined && oldArrayList != null && oldArrayList != "") {
            for (var i in oldArrayList) {
                var al = oldArrayList[i];
                arrayList.push(al);
            }
        }
        var newArrayList = [];
        for (var i in arrayList) {
            var al = arrayList[i];
            al.nal = "10001";
            //判断等式
            if (al.equation == undefined || al.equation == null || al.equation == "") {
                al.equation = "1"
            }
            //判断连接
            if (al.andOr == undefined || al.andOr == null || al.andOr == "") {
                al.andOr = "and"
            }
            //判断值
            if (al.value == undefined || al.value == null || al.value == "") {
                continue;
            }
            newArrayList.push(al);
        }
        ka_grid_findValue.set(config.id, newArrayList);
    },
    setFSV: function (config, al) {//设置排序字段
        //判断等式
        if (al.field == undefined || al.field == null || al.field == "") {
            // layer.msg('请设置需要排序！');
        } else {
            if (al.orderby == undefined || al.orderby == null || al.orderby == "") {
                al.orderby = "descending";
            }
            ka_grid_sortValue.set(config.id, al);
        }
    },
    getHtml: function (config) { // html
        var id = treegrid.rc(config, "id");
        var html = `<table id="LayerKaGrid_` + id + `" style="width: ` + treegrid.rc(config, "width") + `;height: ` + treegrid.rc(config, "height") + `;"  class="ag-theme-balham"></table>`;
        config.id = id;
        return html;
    },
    getData: function (config, cb) { // html
        if (config.dataType == 1) { //1:URL
            var option = kaValue.getUrl(config.url);
            var sortValue = ka_grid_sortValue.get(config.id);
            if (sortValue != undefined && sortValue != null && sortValue != "") {
                if (option.url.indexOf("?") > 0) {
                    option.url = option.url + "&orderByColumn=" + sortValue.field + "&isAsc=" + sortValue.orderby;
                } else {
                    option.url = option.url + "?orderByColumn=" + sortValue.field + "&isAsc=" + sortValue.orderby;
                }
            }
            if (config.fv != undefined && config.fv != null && config.fv != "" && config.fv.length > 0) {
                treegrid.setFV(config, []);
            }
            var findValue = ka_grid_findValue.get(config.id);
            if (findValue != undefined && findValue != null && findValue != "") {
                if (option["data"] == undefined || option["data"] == null) {
                    option["data"] = {};
                }
                option.data["queryParams"] = findValue;
                for (var i in findValue) {
                    var field = findValue[i].field;
                    var value = findValue[i].value;
                    option.data[field] = value;
                }
            }
            var pageSize = ka_grid_pageSize.get(config.id);
            if (pageSize != undefined && pageSize != null && pageSize != "") {
                if (option.url.indexOf("?") > 0) {
                    option.url = option.url + "&pageNum=" + pageSize.curr + "&pageSize=" + pageSize.pageSize;
                } else {
                    option.url = option.url + "?pageNum=" + pageSize.curr + "&pageSize=" + pageSize.pageSize;
                }
            } else {
                if (config.pagination) {
                    if (option.url.indexOf("?") > 0) {
                        option.url = option.url + "&paginationx = 1";
                    } else {
                        option.url = option.url + "&paginationx = 1";
                    }
                } else {
                    if (option.url.indexOf("?") > 0) {
                        option.url = option.url + "&pageNum=" + kaLayuiLaypage.curr + "&pageSize=" + kaLayuiLaypage.limit;
                    } else {
                        option.url = option.url + "?pageNum=" + kaLayuiLaypage.curr + "&pageSize=" + kaLayuiLaypage.limit;
                    }
                }
            }
            option.success = function (re) {
                if (re.code == 200) {
                    if (re.total != undefined && re.total != null && re.total != "") {
                        kalog.outLogs(["URL 表格数据:", re]);
                    } else {
                        if (re.data != undefined && re.data != null && re.data.length > 0) {
                            re.total = re.data.length;
                        } else {
                            re["number"] = 0;
                            re["data"] = [];
                            re["rows"] = [];
                            re["pageNum"] = "";
                            re["pageSize"] = "";
                            re["total"] = "";
                        }
                    }
                    cb(re.data, config);
                }
            }
            ka.ajax(option);
        } else if (config.dataType == 2) { //2:本地JSON
            var option = {
                "url": kaValue.faCtx() + "/static/json/" + config.url,
                "async": true,
            };
            option.success = function (re) {
                if (re.code == 200) {
                    if (re.total != undefined && re.total != null && re.total != "") {
                        kalog.outLogs(["本地JSON 表格数据:", re]);
                    } else {
                        if (re.data != undefined && re.data != null && re.data.length > 0) {
                            re.total = re.data.length;
                        } else {
                            re["number"] = 0;
                            re["data"] = [];
                            re["rows"] = [];
                            re["pageNum"] = "";
                            re["pageSize"] = "";
                            re["total"] = "";
                        }
                    }
                    cb(re.data, config);
                }
            }
            ka.ajax(option);
        } else if (config.dataType == 3) { //3:外站URL
            var option = {
                "url": config.url,
                "async": true,
            };
            option.success = function (re) {
                if (re.code == 200) {
                    if (re.total != undefined && re.total != null && re.total != "") {
                        re.total = re.data.length;
                    } else {
                        if (re.data != undefined && re.data != null && re.data.length > 0) {
                            kalog.outLogs(["外站URL 表格数据:", re]);
                        } else {
                            re["total"] = 0;
                            re["data"] = [];
                            re["rows"] = [];
                            re["pageNum"] = "";
                            re["pageSize"] = "";
                            re["total"] = "";
                        }
                    }
                    cb(re.data, config);
                }
            }
            ka.ajax(option);
        } else if (config.dataType == 4) { //4:自定义JSON
            var re = {
                "data": config.url
            }
            kalog.outLogs(["自定义JSON 表格数据:", re]);
            cb(re.data, config);
        }
    },
    topMenuHtml: function (config) { //顶部菜单按钮
        var topMenuButtons = config.topbutton;
        if (topMenuButtons != undefined && topMenuButtons != null && topMenuButtons != "") {
            var buttonData = topMenuButtons.datajson;
            var buttonType = topMenuButtons.type;
            if (buttonType != 0) {
                if(buttonData == undefined || buttonData == null || buttonData == ""){
                    return ``;
                }
            }
            var opt = {};
            if (buttonType == 0) { //0:系统自带
                var option = kaValue.getUrl("getTopButtonQuery");
                option.url = option.url + "?gridId=" + config.grid;
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        var buttons = re.data;
                        for(var k in buttons){
                            buttons[k].cb = function() {
                                var buttonids = this.buttonids;
                                ka.exec(this.data);
                            }
                        }
                        opt.button = buttons;
                    }
                }
                option.error = function (re) {
                    return false;
                }
                ka.ajax(option);
            } else if (buttonType == 1) { //1:URL
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = kaValue.getUrl(buttonData);
                    option.async = false;
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                        return false;
                     }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 2) { //2:本地JSON
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = {
                        "url": kaValue.faCtx() + "/static/json/" + buttonData,
                        "async": false,
                    };
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                        return false;
                     }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 3) { //3:外站URL
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = {
                        "url": buttonData,
                        "async": false,
                    };
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                        return false;
                     }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 4) { //4:自定义JSON
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    opt.button = buttonData;
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            }
            if(opt.button == undefined || opt.button == 0){
                return ``;
            }
            var button = opt.button;
            kaOptionTopMenuButtonMaps = new Map();
            var html = `<div class="layui-btn-group">`;
            for (var i in button) {
                var buttonids = "kabutton" + ka.uuidStr();
                var ico = ``;
                if (button[i].ico != undefined && button[i].ico != null && button[i].ico != "") {
                    ico = `<i class="icon iconfont ` + button[i].ico + ` kaGrid_i"></i>`;
                }
                html = html + `
                    <button id="` + buttonids + `" onclick="treegrid.topMenuClick('` + buttonids + `')" type="button" class="layui-btn-primary layui-border-blue layui-btn-sm kaGrid_button">`
                    + ico + button[i].title +
                    `</button>
                `;
                button[i].buttonids = buttonids;
                kaOptionTopMenuButtonMaps.set(buttonids, button[i]);
            }
            html = html + `</div>`;
            return html;
        } else {
            return ``;
        }
    },
    topMenuClick: function (buttonids) {
        var button = kaOptionTopMenuButtonMaps.get(buttonids)
        button.cb(button.gridConfig);
    },
    getColumnDefs: function (config, kaposition) { // html
        var gct = config.gridcolumnType;//字段类型【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
        var columnDefs = [];
        if (gct == 0) {
            if (config.column != undefined && config.column != null && config.column != "") {
                var option = kaValue.getUrl("getColumnByGrid");
                option.url = option.url + "/" + config.column;
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        var cds = re.data;
                        for (var j in cds) {
                            var boolean = false;
                            var showPosition = cds[j].showPosition;
                            if (showPosition != undefined && showPosition != null && showPosition != "") {
                                var showPositionArray = showPosition.split(",");
                                for (var i in showPositionArray) {
                                    if (showPositionArray[i] == "1000" || showPositionArray[i] == kaposition) {
                                        boolean = true;
                                        break;
                                    }
                                }
                            }
                            if (boolean) {
                                columnDefs.push(cds[j]);
                            }
                        }
                    }
                }
                ka.ajax(option);
            } else { // 加载字段后台字段
                columnDefs = [];
            }
        } else if (gct == 1) { //1:URL
            if (config.column != undefined && config.column != null && config.column != "") {
                var option = kaValue.getUrl(config.column);
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        var cds = re.data;
                        for (var j in cds) {
                            var boolean = false;
                            var showPosition = cds[j].showPosition;
                            if (showPosition != undefined && showPosition != null && showPosition != "") {
                                var showPositionArray = showPosition.split(",");
                                for (var i in showPositionArray) {
                                    if (showPositionArray[i] == "1000" || showPositionArray[i] == kaposition) {
                                        boolean = true;
                                        break;
                                    }
                                }
                            }
                            if (boolean) {
                                columnDefs.push(cds[j]);
                            }
                        }
                    }
                }
                ka.ajax(option);
            } else { // 加载字段后台字段
                columnDefs = [];
            }
        } else if (gct == 2) { //2:本地JSON
            if (config.column != undefined && config.column != null && config.column != "") {
                var option = {
                    "url": kaValue.faCtx() + "/static/json/" + config.column,
                    "async": false,
                };
                option.success = function (re) {
                    if (re.code == 200) {
                        columnDefs = re.data;
                    }
                }
                ka.ajax(option);
            } else { // 加载字段后台字段
                columnDefs = [];
            }
        } else if (gct == 3) { //3:外站URL
            if (config.column != undefined && config.column != null && config.column != "") {
                var option = {
                    "url": config.column,
                    "async": false,
                };
                option.success = function (re) {
                    if (re.code == 200) {
                        var cds = re.data;
                        for (var j in cds) {
                            var boolean = false;
                            var showPosition = cds[j].showPosition;
                            if (showPosition != undefined && showPosition != null && showPosition != "") {
                                var showPositionArray = showPosition.split(",");
                                for (var i in showPositionArray) {
                                    if (showPositionArray[i] == "1000" || showPositionArray[i] == kaposition) {
                                        boolean = true;
                                        break;
                                    }
                                }
                            }
                            if (boolean) {
                                columnDefs.push(cds[j]);
                            }
                        }
                    }
                }
                ka.ajax(option);
            } else { // 加载字段后台字段
                columnDefs = [];
            }
        } else if (gct == 4) { //4:自定义JSON
            if (config.column != undefined && config.column != null && config.column != "" && config.column.length > 0) {
                columnDefs = config.column;
            } else { // 加载字段后台字段
                columnDefs = [];
            }
        }
        return columnDefs;
    },
    getQueryColumn: function (config) { //字段
        var kaposition = config.kaposition;//默认（1003）显示位置【1001:编辑,1002:新增,1003:列表,1004:列表查询,1005:选择带回列表,1006:选择带回列表查询,1007:上查列表,1008:上查列表查询,1009:下查列表,1010:下查列表查询】
        kaposition = (config.kaposition == "1003" ? "1004" : config.kaposition == "1005" ? "1006" : config.kaposition == "1007" ? "1008" : config.kaposition == "1009" ? "1010" : "");
        var columnDefs = treegrid.getColumnDefs(config, kaposition);
        return columnDefs;
    },
    getColumn: function (config, kaposition) { // html
        var gin = config.gridIsnumber; //显示序号【0:不显示,1:显示】
        var gic = config.gridIscheckbox; //显示序号【0:不显示,1:显示】
        var button = config.button;
        var kaposition = config.kaposition;//默认（1003）显示位置【1001:编辑,1002:新增,1003:列表,1004:列表查询,1005:选择带回列表,1006:选择带回列表查询,1007:上查列表,1008:上查列表查询,1009:下查列表,1010:下查列表查询】
        if (kaposition == undefined || kaposition == null || kaposition == "") {
            kaposition = "1003";
        }
        var columnDefs = treegrid.getColumnDefs(config, kaposition);
        //组装 字段列表
        var cols = [];
        //判断用户自定义 -- 序号
        if (gin == 1) {
            cols.push({
                title: '', 
                fixed: 'left',
                width: 50,
                align: 'center',
                noci: 0,
                templet: function(d){
                    return `<div style="margin-left: -10px;padding-right: 10px;background: #fafafa;">` + d.LAY_NUM + `</div>`;
                }
            });
        }
        //判断用户自定义 -- 复选框
        if (gic == 1) {
            cols.push({type: 'checkbox', fixed: 'left',noci: 0});
        }
        //加载按钮
        treegrid.rowButton(button, cols, config);
        //加载其他字段
        for (var i in columnDefs) {
            var cs = columnDefs[i];
            cs["kaconfig"] = config;
            var dt = cdMap.get(cs.field);
            if (dt != undefined && dt != null && dt != "") {
                if (cs["width"] == undefined || cs["width"] == null || cs["width"] == "") {
                    var kawidth = treegrid.convertWidth(cs.field);
                    cs["width"] = kawidth;
                    cs["minWidth"] = kawidth;
                    cs["maxWidth"] = kawidth;
                }
                cs.templet = function (d) {
                    var value = d[d.LAY_COL.field];
                    if (value != undefined && value != null) {
                        value = treegrid.convertData(value, d.LAY_COL.field);
                        return `<a href="javascript:void(0);" onclick="alert('` + d.id + `');">` + value + `</a>`;
                    } else {
                        return value;
                    }
                }
            } else if (columnDefs[i].dataType == 2) {
                // cs["headerClass"] = 'ag-header-center';
                // cs["cellStyle"] = { "text-align": "center" };
                if (cs["width"] == undefined || cs["width"] == null || cs["width"] == "") {
                    cs["width"] = 90;
                    cs["minWidth"] = 90;
                    cs["maxWidth"] = 90;
                }
                cs.templet = function (d) {
                    var value = d[d.LAY_COL.field];
                    if (value != undefined && value != null) {
                        value = treegrid.convertData2((d.LAY_COL.field == "delFlag" || d.LAY_COL.field == "del_flag")?"sys_del_flag":d.LAY_COL.code, d[d.LAY_COL.field]);
                        return `<a href="javascript:void(0);" onclick="alert('` + d.id + `');">` + value + `</a>`;
                    } else {
                        return value;
                    }
                }
            }
            // 创建时间
            if (cs.field == "createTime" || cs.field == "updateTime") {
                cs["width"] = 150;
                cs["minWidth"] = 150;
                cs["maxWidth"] = 150;
            }
            // 创建时间
            if (cs.field == "code" || cs.field == "code") {
                cs["width"] = 150;
                cs["minWidth"] = 150;
                cs["maxWidth"] = 150;
            }
            cs["kaconfig"] = config
            cols.push(cs);
        }
        return cols;
    },
    rowButton: function (button, cols, config) { //行菜单按钮
        if(button == undefined){
            return false;
        }
        if(button.type == undefined){
            return false;
        }
        kaOptionButtonMaps = new Map();
        if (button != undefined && button != null && button != "") {
            var buttonType = button.type;
            var buttonData = button.datajson;
            var opt = {
                headerName: '操作',
                title: '操作',
                pinned: "left",
                field: 'kaOptionButtons',
                fieldName: 'kaOptionButtons',
                headerClass: 'ag-header-center',
                suppressMenu: true,
                cellStyle: { "text-align": "center" },
                buttonType: buttonType, //【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
                button: buttonData,
                noci: 0,
                kaconfig: config
            };
            opt["kaSort"] = false;
            opt["suppressMenu"] = true;
            if (buttonType == 0) { //0:系统自带
                var option = kaValue.getUrl("getButtonQuery");
                option.url = option.url + "?gridId=" + config.grid;
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        var buttons = re.data;
                        for(var k in buttons){
                            buttons[k].dataJsonStr = buttons[k].data;
                            buttons[k].cb = function() {
                                top.ka_grid_rowsMap.set(d.data.id,d);
                                ka.exec("var buttonidsStrId = '" + d.data.id + "';var d = top.ka_grid_rowsMap.get(buttonidsStrId);" + this.dataJsonStr);
                            }
                        }
                        opt.button = buttons;
                    }
                }
                option.error = function (re) {
                    return false;
                 }
                ka.ajax(option);
            } else if (buttonType == 1) { //1:URL
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = kaValue.getUrl(buttonData);
                    option.async = false;
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                        return false;
                     }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 2) { //2:本地JSON
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = {
                        "url": kaValue.faCtx() + "/static/json/" + buttonData,
                        "async": false,
                    };
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                       return false;
                    }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 3) { //3:外站URL
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    var option = {
                        "url": buttonData,
                        "async": false,
                    };
                    option.success = function (re) {
                        if (re.code == 200) {
                            var buttons = re.data;
                            opt.button = buttons;
                        }
                    }
                    option.error = function (re) {
                        return false;
                     }
                    ka.ajax(option);
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            } else if (buttonType == 4) { //4:自定义JSON
                if (buttonData != undefined && buttonData != null && buttonData != "") {
                    opt.button = buttonData;
                } else { // 加载字段后台字段
                    opt.button = [];
                    return false;
                }
            }
            if(opt.button == undefined || opt.button == 0){
                return false;
            }
            var withs = 0;
            for (var i in opt.button) {
                var ws = opt.button[i].title.length * 30;
                if (withs <= ws) {
                    withs = ws;
                }
            }
            withs = withs + 10;
            opt["width"] = withs;
            opt["minWidth"] = withs;
            opt["maxWidth"] = withs;
            opt["cellStyle"] = { "text-align": "center" };
            opt.templet = function (d) {
                var button = d.LAY_COL.kaconfig.button.datajson;
                var buttonids = "kabutton" + ka.uuidStr();
                var newButtons = [];
                for (var i in button) {
                    var newButton = {}
                    $.extend(newButton, button[i]);
                    newButton.data = d;
                    newButtons.push(newButton);
                }
                kaOptionButtonMaps.set(buttonids, newButtons);
                if (button.length == 1) {
                    return `<a id="` + button[0].id + `" href="javascript:void(0);" onclick="treegrid.singleCbB('` + buttonids + `');">` + button[0].title + `</a>`;
                } else if (button.length > 1) {
                    var html = `
                        <a id="` + buttonids + `" href="javascript:void(0);" onclick="treegrid.dropdownOpen(this)">
                            <span>更多</span>
                            <i class="layui-icon layui-icon-down layui-font-12"></i>
                        </a>
                    `
                    return html;
                }
            }
            cols.push(opt);
        }
    },
    loading: function (config) {
        ka_grid_config_div.set(config.id,config);
        var option = kaValue.getUrl("getGrid");
        option.url = option.url + "/" + config.id;
        option.success = function (re) {
            if (re.code == 200) {
                $.extend(config, re.grids)
                config.id = config.code;
                if (config.gridcolumnType == 0) {
                    config.column = re.grids.id;
                    config.grid = re.grids.id;
                }
                // var option = kaValue.getUrl("folderList");
                treegrid.getData(config, function (reData, config) {  //将列和数据赋给gridOptions 
                    if (config.gridcolumnType == 0) {
                        config.column = re.grids.id;
                        config.grid = re.grids.id;
                    }
                    var topMenuHtml = treegrid.topMenuHtml(config);
                    var columnDefs = treegrid.getColumn(config);
                    var elemId = '#LayerKaGrid_' + config.id;
                    if (topMenuHtml != "") {
                        var faHtml = `
                            <div id="AgKaGrid_` + config.id + `_topMenu">` + topMenuHtml +`</div><div id="AgKaGrid_` + config.id + `_queryList" class="kaQueryList" style="margin-bottom: 5px;display: none;"></div>
                        `;
                        $("#toolbarTreeGrid").html(faHtml);
                    } else {
                        var faHtml = `
                            <div id="AgKaGrid_` + config.id + `_queryList" class="kaQueryList" style="margin-bottom: 5px;display: none;"></div>
                        `;
                        $("#toolbarTreeGrid").html(faHtml);
                    }
                    layui.treeTable.render({
                        id: elemId,
                        elem: elemId,
                        data: reData, // 此处为静态模拟数据，实际使用时需换成真实接口
                        height: 'full-30',
                        toolbar: '#toolbarTreeGrid',
                        defaultToolbar: ['filter', 'exports', 'print'],
                        tree: {
                            data: {
                                cascade: "none"
                            },
                            view: {
                                expandAllDefault: true,
                                iconClose: `<img src="static/images/iconClose.png" style="width: 16px;height: 16px;margin-right: 5px;margin-top: -3px;"/>`,
                                iconOpen: `<img src="static/images/iconOpen.png" style="width: 18px;height: 18px;margin-right: 5px;margin-top: -3px;"/>`,
                                iconLeaf: `<img src="static/images/iconLeaf.png" style="width: 16px;height: 14px;margin-left: -5px;margin-right: 5px;margin-top: -3px;"/>`
                            }
                        },
                        cols: [columnDefs],
                        page: false,
                        done: function(res, curr, count, origin){
                            
                        }
                    });
                    var fileds = [];
                    var filedsColumnTypes = [];
                    var filedsDataTypes = [];
                    for (var k in columnDefs) {
                        if (columnDefs[k].noci != 0) {
                            fileds.push(columnDefs[k].field);
                            filedsColumnTypes.push(columnDefs[k].columnType);
                            filedsDataTypes.push(columnDefs[k].dataType);
                            if (fileds.length == 1) {
                                break;
                            }
                        }
                    }
                    treegrid.queryFeildLoade(config, fileds, filedsColumnTypes, filedsDataTypes, []); //
                    treegrid.queryFeildLoadeHtml(config);
                    treegrid.queryFeildValue(config.id);
                });

            } else {
                setTimeout(function () {
                    kaMsg.error(re);
                }, 500);
            }
        }
        ka.ajax(option);
    },
    queryFeildLoade: function (config, qfds, filedsColumnTypes, filedsDataTypes, filedsDataValues) { //查询字段加载
        //初始化查询字段
        var boolean = false;
        var list = [];
        if (ka_grid_QueryType.get(config.id) != undefined && ka_grid_QueryType.get(config.id) != null) {
            list = ka_grid_QueryType.get(config.id);
        }
        if (qfds != undefined && qfds != null) {
            for (var i in qfds) {
                var blnum = 0;
                for(var j in list){
                    if(list[j].qfd == qfds[i]){
                        blnum = j;
                        break;
                    }
                    blnum = blnum + 1;
                }
                var returnData = treegrid.queryFeildHtml(config,blnum);
                returnData.qfd = qfds[i];
                returnData.columnTypes = filedsColumnTypes[i];
                returnData.dataTypes = filedsDataTypes[i];
                list.push(returnData);
                var queryType = "";
                if (filedsColumnTypes[i] == "varchar" || filedsColumnTypes[i] == "longtext") {
                    queryType = "109";
                    var fbAnd = config.fbAnd;
                    if(fbAnd){
                        queryType = "101";
                    }
                } else if (filedsColumnTypes[i] == "int" || filedsColumnTypes[i] == "double") {
                    queryType = "101";
                } else if (filedsColumnTypes[i] == "datetime") {
                    queryType = "101";
                } else {
                    queryType = "109";
                    var fbAnd = config.fbAnd;
                    if(fbAnd){
                        queryType = "101";
                    }
                }
                var fdv = "";
                if (filedsDataValues.length > 0) {
                    fdv = filedsDataValues[i];
                }
                var queryValue = {
                    queryFilter: qfds[i],
                    queryType: queryType,
                    dataType: returnData.dataTypes,
                    queryValue: fdv,
                    andOr: "and"
                };
                ka_grid_QueryValue.set(returnData.uuid, queryValue);
                boolean = true;
            }
        }
        if (boolean) {
            ka_grid_QueryType.set(config.id, list);
        }
    },
    queryFeildLoadeHtml: function (config) {//渲染到页面
        var kagid = "AgKaGrid_" + (config.id);
        $("#" + kagid + "_queryList").html("");
        var queryFeildList = ka_grid_QueryType.get(config.id);
        var booleanStr = false;
        var uuidstr = ka.uuidStr();
        for (var z in queryFeildList) {
            var queryFeildHtml = "";
            var returnData = queryFeildList[z];
            queryFeildHtml = returnData.html;
            if (queryFeildHtml != "") {
                queryListxx = `<div id="layuiForm` + uuidstr + `" lay-filter="layuiForm` + uuidstr + `" class="layui-form" style="width: 100%;"></div>`
                $("#" + kagid + "_queryList").html(queryListxx);
                $("#layuiForm" + uuidstr).append(queryFeildHtml);
                layui.form.on('select(queryFilter_' + returnData.uuid + ')', function (data) {
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值z
                    var uuidStr = $(elem).attr("uuid");
                    var configid = $(elem).attr("configid");
                    var columnType = $("#query_filter_option_" + uuidStr + "_" + value).attr("columntype");
                    var dataType = $("#query_filter_option_" + uuidStr + "_" + value).attr("dataType");
                    var queryValue = ka_grid_QueryValue.get(uuidStr);
                    if (queryValue == undefined || queryValue == null) {
                        var queryType = "";
                        if (columnType == "varchar" || columnType == "longtext") {
                            queryType = "109";
                            var fbAnd = config.fbAnd;
                            if(fbAnd){
                                queryType = "101";
                            }
                        } else if (columnType == "int" || columnType == "double") {
                            queryType = "101";
                        } else if (columnType == "datetime") {
                            queryType = "101";
                        } else {
                            queryType = "109";
                            var fbAnd = config.fbAnd;
                            if(fbAnd){
                                queryType = "101";
                            }
                        }
                        queryValue = {
                            queryFilter: value,
                            queryType: queryType,
                            dataType: dataType,
                            queryValue: "",
                            andOr: "and"
                        };
                    } else {
                        var queryType = "";
                        if (columnType == "varchar" || columnType == "longtext") {
                            queryType = "109";
                            var fbAnd = config.fbAnd;
                            if(fbAnd){
                                queryType = "101";
                            }
                        } else if (columnType == "int" || columnType == "double") {
                            queryType = "101";
                        } else if (columnType == "datetime") {
                            queryType = "101";
                        } else {
                            queryType = "109";
                            var fbAnd = config.fbAnd;
                            if(fbAnd){
                                queryType = "101";
                            }
                        }
                        queryValue = {
                            queryFilter: value,
                            queryType: queryType,
                            queryValue: "",
                            andOr: "and"
                        };
                    }
                    var list = ka_grid_QueryType.get(configid);
                    for (var j in list) {
                        if (list[j].uuid == uuidStr) {
                            list[j].qfd = value;
                            break;
                        }
                    }
                    ka_grid_QueryType.set(config.id, list);
                    ka_grid_QueryValue.set(uuidStr, queryValue);
                    treegrid.queryFeildValue(configid);
                });
                layui.form.on('select(queryTypeSelect_' + returnData.uuid + ')', function (data) {
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值
                    var uuidStr = $(elem).attr("uuid");
                    var configid = $(elem).attr("configid");
                    var queryValue = ka_grid_QueryValue.get(uuidStr);
                    queryValue.queryType = value;
                    ka_grid_QueryValue.set(uuidStr, queryValue);
                    treegrid.queryFeildValue(configid);
                });
                booleanStr = true;
                if (queryFeildList.length == 1) {
                    $("#andOr_" + returnData.uuid).hide();
                }
                $("#addQuery_" + returnData.uuid).show();
                $("#queryButton_" + returnData.uuid + "_div").show();
                break;
            }
        }
        if (booleanStr) {
            layui.form.render();
            $("#" + kagid + "_queryList").show();
        }
    },
    queryFeildHtml: function (config,num) { //查询字段
        var uuid = ka.uuidStr();
        var returnData = {
            uuid: uuid,
            html: "",
            columnDefs: [],
            columnType: "",
            dataType: "",
            showPosition: "",
            config: config
        }
        var fb = config.fb;
        var fbAnd = config.fbAnd;
        var html = ``;
        if (fb) {
            var columnDefs = treegrid.getQueryColumn(config);
            var feildHtml = ``;
            for (var i in columnDefs) {
                var pyna = kaZhPinYinArray(columnDefs[i].headerName);
                var swStr = "";
                var swxxStr = "";
                for (var j in pyna) {
                    swStr = swStr + pyna[j][0].toUpperCase()
                    swxxStr = swxxStr + pyna[j][0].toLowerCase();
                }
                feildHtml = feildHtml + `<option id="query_filter_option_` + uuid + `_` + columnDefs[i].field + `" code="` + columnDefs[i].code + `" dataType="` + columnDefs[i].dataType + `" columnType="` + columnDefs[i].columnType + `" optionId="` + swxxStr + `" value="` + columnDefs[i].field + `">` + columnDefs[i].headerName + `</option>\r\n`;
                returnData.columnDefs.push(columnDefs[i]);
                returnData.showPosition = (columnDefs[i].showPosition != undefined && columnDefs[i].showPosition != null && columnDefs[i].showPosition != "") ? columnDefs[i].showPosition : "1000";
            }
            var mhtml = ``;
            if(num == 0){
                mhtml = `margin-left: 5px;`;
            }
            var andOr_html = `
                <option value="and">并且</option>
                <option value="or">或者</option>
            `;
            if(fbAnd){
                andOr_html = `
                    <option value="and">并且</option>
                `;
            }
            html = html + `
            <div id="layuiRow_querylist_` + uuid + `" class="layui-row layuiRow_querylist_` + config.id + `" style="margin-top: 5px;">
                <div class="layui-col-xs9" style="width: 515px;` + mhtml + `">
                    <div class="layui-row">
                        <div class="layui-col-xs2" style="padding-right: 5px;padding-left: 1px;width: 140px;">
                            <select id="queryFilter_` + uuid + `" configid="` + config.id + `" uuid="` + uuid + `" name="queryFilter" lay-filter="queryFilter_` + uuid + `">
                                ` + feildHtml + `
                            </select>
                        </div>
                        <div class="layui-col-xs2" id="queryType_` + uuid + `" style="padding-left: 5px;padding-right: 5px;width: 120px;">
                            <select id="queryTypeSelect_` + uuid + `" configid="` + config.id + `" uuid="` + uuid + `" name="queryType" lay-filter="queryTypeSelect_` + uuid + `">
                            </select>
                        </div>
                        <div class="layui-col-xs3" id="queryValue_` + uuid + `" style="padding-left: 5px;padding-right: 5px;width: 170px;">
                            <input onChange="treegrid.queryValueChange('` + uuid + `','` + config.id + `')" type="text" id="queryValueSelect_` + uuid + `" configid="` + config.id + `" uuid="` + uuid + `" name="queryValue" lay-filter="queryValueSelect_` + uuid + `" class="layui-input">
                        </div>
                        <div class="layui-col-xs1" id="andOr_` + uuid + `" style="padding-left: 5px;padding-right: 5px;width: 65px;">
                            <select id="andOrSelect_` + uuid + `" configid="` + config.id + `" uuid="` + uuid + `" name="andOr" lay-filter="andOrSelect_` + uuid + `">
                                ` + andOr_html + `
                            </select>
                        </div>
                        <div class="layui-col-xs1" id="delete_` + uuid + `" onclick="treegrid.deleteQueryValue(this)" configid="` + config.id + `" uuid="` + uuid + `" queryButtonId="addQuery_` + uuid + `" layuidropdownId="queryButtonIdaddQuery_` + uuid + `" style="width: 15px;height: 30px;line-height: 48px;text-align: center;display: none;">
                            <i class="icon iconfont icon-minus" style="font-size: 10px;padding: 1px;padding-top: 0px;padding-bottom: 0px;border: 1px solid #0066ff;color: #030303;background: #0066ff1c;"></i>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2" id="addQuery_` + uuid + `" style="width: auto;display: none;">
                    <button id="addQuery_` + uuid + `" type="button" onclick="treegrid.openAddQueryFeildView('addQuery_` + uuid + `','` + config.id + `');" class="layui-btn-primary layui-border-blue layui-btn-xs" style="cursor: pointer;height: 30px;line-height: 30px;padding: 0 4px;border: 0px;">
                        <i class="icon iconfont icon-angle-double-down"></i>
                    </button>
                </div>
                <div id="queryButton_` + uuid + `_div" class="layui-col-xs2" style="padding-left: 5px;padding-right: 5px;display: none;">
                    <a id="queryButton_` + uuid + `" onclick="treegrid.queryData('` + config.id + `');" class="layui-btn layui-btn-sm">
                        <i class="icon iconfont icon-search" style="font-size: 11px;margin-right: 5px;"></i>查询
                    </a>
                </div>
            </div>
            `;
            returnData.html = html;
        }
        return returnData
    },
    queryData: function (configid) {
        var queryFeildList = ka_grid_QueryType.get(configid);
        var config = ka_grid_config_div.get(configid);
        var arrayList = [];
        for (var z in queryFeildList) {
            var returnData = queryFeildList[z];
            var uuid = returnData.uuid;
            var gridQueryValue = ka_grid_QueryValue.get(uuid);
            var json = {
                field: gridQueryValue.queryFilter,
                equation: gridQueryValue.queryType,
                andOr: gridQueryValue.andOr,
                value: gridQueryValue.queryValue
            }
            arrayList.push(json);
        }
        // nal
        var newArrayList = [];
        var oldArrayList = ka_grid_findValue.get(config.id);
        for (var j in oldArrayList) {
            if (oldArrayList[j].nal != "10001") {
                newArrayList.push(oldArrayList[j]);
            }
        }
        ka_grid_findValue.set(config.id, newArrayList);
        treegrid.setFV(config, arrayList);
        treegrid.getData(config, function (reData, config) {
            layui.treeTable.reloadData('#LayerKaGrid_' + config.id, {
                url: null,
                data: reData
            });
        })
    },
    queryValueChange: function (uuid, configid, that) {
        var value = $(that).val();
        var fromValue = ka_grid_QueryValue.get(uuid);
        fromValue.queryValue = value;
        ka_grid_QueryValue.set(uuid, fromValue);
    },
    deleteQueryValue: function (that) {
        var configid = $(that).attr("configid");
        var uuid = $(that).attr("uuid");
        var layuidropdownId = "";
        var uuidOne = "";
        var queryFeildList = ka_grid_QueryType.get(configid);
        var queryFeildNewList = [];
        for (var z in queryFeildList) {
            var returnData = queryFeildList[z];
            if (z == 0) {
                layuidropdownId = "queryButtonIdaddQuery_" + returnData.uuid
                uuidOne = "addQuery_" + returnData.uuid;
            }
            if (uuid != returnData.uuid) {
                queryFeildNewList.push(returnData);
            } else {
                ka_grid_QueryValue.delete(uuid);
            }
        }
        ka_grid_QueryType.set(configid, queryFeildNewList);
        layui.dropdown.close(layuidropdownId);
        treegrid.openAddQueryFeildView(uuidOne, configid);
        layui.dropdown.open(layuidropdownId);
    },
    addQueryFeild: function (that) {
        var id = $(that).attr("id");
        var layuidropdownId = $(that).attr("layuidropdownId");
        var queryButtonId = $(that).attr("queryButtonId");
        var configid = $(that).attr("configid");
        var config = ka_grid_config_div.get(configid);
        var value = $("#" + id).val();
        var uuid = $(that).attr("uuid");
        var columnDefs = treegrid.getQueryColumn(config);
        var fileds = [];
        var filedsColumnTypes = [];
        var filedsDataTypes = [];
        for (var k in columnDefs) {
            if (columnDefs[k].noci != 0 && columnDefs[k].field == value) {
                fileds.push(columnDefs[k].field);
                filedsColumnTypes.push(columnDefs[k].columnType);
                filedsDataTypes.push(columnDefs[k].dataType);
                boolean = true;
                break;
            }
        }
        treegrid.queryFeildLoade(config, fileds, filedsColumnTypes, filedsDataTypes, []); //
        treegrid.openAddQueryFeildView(queryButtonId, configid);
        layui.dropdown.close(layuidropdownId);
        layui.dropdown.open(layuidropdownId);
    },
    openAddQueryFeildView: function (queryButtonId, configid) {
        var content = ``;
        var queryFeildList = ka_grid_QueryType.get(configid);
        var uuidstrArry = [];
        for (var z in queryFeildList) {
            if (z >= 1) {
                var uuidstr = ka.uuidStr();
                var returnData = queryFeildList[z];
                content = content +
                    `<div id="layuiForm` + uuidstr + `" lay-filter="layuiForm` + uuidstr + `" class="layui-form" style="width: 100%;">` +
                    returnData.html +
                    `</div>`;
                uuidstrArry.push(uuidstr);
                $("#andOr_" + queryFeildList[0].uuid).show();
            }
        }
        var config = ka_grid_config_div.get(configid);
        var fbAnd = config.fbAnd;
        var list = [];
        if (ka_grid_QueryType.get(config.id) != undefined && ka_grid_QueryType.get(config.id) != null) {
            list = ka_grid_QueryType.get(config.id);
        }
        var columnDefs = treegrid.getQueryColumn(config);
        var feildHtml = ``;
        for (var i in columnDefs) {
            if(fbAnd){
                var boolean = false;
                for(var j in list){
                    if(list[j].qfd == columnDefs[i].field){
                        boolean = true;
                        break;
                    }
                }
                if(boolean){
                    continue;
                }
            }
            feildHtml = feildHtml + `<option value="` + columnDefs[i].field + `">` + columnDefs[i].headerName + `</option>\r\n`;
        }
        content = content + `
            <div style="width: 100%;line-height: 26px;height: 26px;">
                <select id="addQueryFeild_div_` + queryButtonId + `" layuidropdownId="queryButtonId` + queryButtonId + `" queryButtonId="` + queryButtonId + `" configid="` + configid + `" uuid="` + uuidstrArry.join(",") + `" name="addQueryFeildValue" onChange="treegrid.addQueryFeild(this)" style="border: 0px solid;margin-left: 0px;color: #06f;font-size: 12.4px;padding-left: 0px;">
                    <option value="">请选择查询字段</option>\r\n
                    ` + feildHtml + `
                </select>
            </div>`;
        layui.dropdown.render({
            id: "queryButtonId" + queryButtonId,
            elem: '#' + queryButtonId,
            content: content,
            align: 'right',
            className: 'add_query_feild_div_dropdown_tabs',
            ready: function () {
                var endStr = "";
                for (var z in queryFeildList) {
                    var returnData = queryFeildList[z];
                    if (z >= 1) {
                        $("#delete_" + returnData.uuid).show();
                        $("#queryButton_" + returnData.uuid + "_div").hide();
                        $("#addQuery_" + returnData.uuid).hide();
                        layui.form.on('select(queryFilter_' + returnData.uuid + ')', function (data) {
                            var elem = data.elem; // 获得 select 原始 DOM 对象
                            var value = data.value; // 获得被选中的值z
                            var uuidStr = $(elem).attr("uuid");
                            var configid = $(elem).attr("configid");
                            var columnType = $("#query_filter_option_" + uuidStr + "_" + value).attr("columntype");
                            var dataType = $("#query_filter_option_" + uuidStr + "_" + value).attr("dataType");
                            var queryValue = ka_grid_QueryValue.get(uuidStr);
                            if (queryValue == undefined || queryValue == null) {
                                var queryType = "";
                                if (columnType == "varchar" || columnType == "longtext") {
                                    queryType = "109";
                                    var fbAnd = config.fbAnd;
                                    if(fbAnd){
                                        queryType = "101";
                                    }
                                } else if (columnType == "int" || columnType == "double") {
                                    queryType = "101";
                                } else if (columnType == "datetime") {
                                    queryType = "101";
                                } else {
                                    queryType = "109";
                                    var fbAnd = config.fbAnd;
                                    if(fbAnd){
                                        queryType = "101";
                                    }
                                }
                                queryValue = {
                                    queryFilter: value,
                                    queryType: queryType,
                                    dataType: dataType,
                                    queryValue: "",
                                    andOr: "and"
                                };
                            } else {
                                var queryType = "";
                                if (columnType == "varchar" || columnType == "longtext") {
                                    queryType = "109";
                                    var fbAnd = config.fbAnd;
                                    if(fbAnd){
                                        queryType = "101";
                                    }
                                } else if (columnType == "int" || columnType == "double") {
                                    queryType = "101";
                                } else if (columnType == "datetime") {
                                    queryType = "101";
                                } else {
                                    queryType = "109";
                                    var fbAnd = config.fbAnd;
                                    if(fbAnd){
                                        queryType = "101";
                                    }
                                }
                                queryValue = {
                                    queryFilter: value,
                                    queryType: queryType,
                                    queryValue: "",
                                    andOr: "and"
                                };
                            }
                            var list = ka_grid_QueryType.get(configid);
                            for (var j in list) {
                                if (list[j].uuid == uuidStr) {
                                    list[j].qfd = value;
                                    break;
                                }
                            }
                            ka_grid_QueryType.set(configid, list);
                            ka_grid_QueryValue.set(uuidStr, queryValue);
                            treegrid.queryFeildValue(configid);
                        });
                        layui.form.on('select(queryTypeSelect_' + returnData.uuid + ')', function (data) {
                            var elem = data.elem; // 获得 select 原始 DOM 对象
                            var value = data.value; // 获得被选中的值
                            var uuidStr = $(elem).attr("uuid");
                            var configid = $(elem).attr("configid");
                            var queryValue = ka_grid_QueryValue.get(uuidStr);
                            queryValue.queryType = value;
                            ka_grid_QueryValue.set(uuidStr, queryValue);
                            treegrid.queryFeildValue(configid);
                        });
                        layui.form.render();
                        endStr = returnData.uuid;
                    }
                }
                $("#andOr_" + endStr).hide();
                treegrid.queryFeildValue(configid);
            }
        });
    },
    queryFeildValue: function (configid) {//渲染参数值
        var config = ka_grid_config_div.get(configid);
        var fbAnd = config.fbAnd;
        var queryFeildList = ka_grid_QueryType.get(configid);
        for (var z in queryFeildList) {
            var returnData = queryFeildList[z];
            // showPosition
            var fromValue = ka_grid_QueryValue.get(returnData.uuid);
            var layerFormId = $("#layuiRow_querylist_" + returnData.uuid).parent().attr("lay-filter");
            if (fromValue == undefined || fromValue == null) {
                fromValue = layui.form.val(layerFormId);
            }
            var columnType = $("#query_filter_option_" + returnData.uuid + "_" + fromValue.queryFilter).attr("columnType");
            var dataType = $("#query_filter_option_" + returnData.uuid + "_" + fromValue.queryFilter).attr("dataType");
            var code = $("#query_filter_option_" + returnData.uuid + "_" + fromValue.queryFilter).attr("code");
            if (columnType == "varchar" || columnType == "longtext") {
                //---------------------类型
                var queryTypeSelectHtml = `
                    <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_102" configid="` + configid + `" value="102">不等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_103" configid="` + configid + `" value="103">大于</option>
                    <option id="query_type_option_` + returnData.uuid + `_104" configid="` + configid + `" value="104">大于等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_105" configid="` + configid + `" value="105">小于</option>
                    <option id="query_type_option_` + returnData.uuid + `_106" configid="` + configid + `" value="106">小于等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_107" configid="` + configid + `" value="107">为空</option>
                    <option id="query_type_option_` + returnData.uuid + `_108" configid="` + configid + `" value="108">不为空</option>
                    <option id="query_type_option_` + returnData.uuid + `_109" configid="` + configid + `" value="109">包含</option>
                    <option id="query_type_option_` + returnData.uuid + `_110" configid="` + configid + `" value="110">不包含</option>
                    <option id="query_type_option_` + returnData.uuid + `_111" configid="` + configid + `" value="111">左包含</option>
                    <option id="query_type_option_` + returnData.uuid + `_112" configid="` + configid + `" value="112">右包含</option>
                `;
                if(fbAnd){
                    queryTypeSelectHtml = `
                        <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    `;
                }
                $("#queryTypeSelect_" + returnData.uuid).html(queryTypeSelectHtml);

            } else if (columnType == "int" || columnType == "double") {
                var queryTypeSelectHtml = `
                    <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_102" configid="` + configid + `" value="102">不等于</option>
                `;
                if(fbAnd){
                    queryTypeSelectHtml = `
                        <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    `;
                }
                $("#queryTypeSelect_" + returnData.uuid).html(queryTypeSelectHtml);
            } else if (columnType == "datetime") {
                var queryTypeSelectHtml = `
                    <option id="query_type_option_` + returnData.uuid + `_113" configid="` + configid + `" value="113">今天</option>
                    <option id="query_type_option_` + returnData.uuid + `_114" configid="` + configid + `" value="114">昨天</option>
                    <option id="query_type_option_` + returnData.uuid + `_115" configid="` + configid + `" value="115">明天</option>
                    <option id="query_type_option_` + returnData.uuid + `_116" configid="` + configid + `" value="116">上周</option>
                    <option id="query_type_option_` + returnData.uuid + `_117" configid="` + configid + `" value="117">本周</option>
                    <option id="query_type_option_` + returnData.uuid + `_118" configid="` + configid + `" value="118">下周</option>
                    <option id="query_type_option_` + returnData.uuid + `_119" configid="` + configid + `" value="119">上个月</option>
                    <option id="query_type_option_` + returnData.uuid + `_120" configid="` + configid + `" value="120">本月</option>
                    <option id="query_type_option_` + returnData.uuid + `_121" configid="` + configid + `" value="121">下个月</option>
                    <option id="query_type_option_` + returnData.uuid + `_122" configid="` + configid + `" value="122">月</option>
                    <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_104" configid="` + configid + `" value="104">大于等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_106" configid="` + configid + `" value="106">小于等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_102" configid="` + configid + `" value="102">不等于</option>
                    <option id="query_type_option_` + returnData.uuid + `_103" configid="` + configid + `" value="103">大于</option>
                    <option id="query_type_option_` + returnData.uuid + `_105" configid="` + configid + `" value="105">小于</option>
                    <option id="query_type_option_` + returnData.uuid + `_107" configid="` + configid + `" value="107">为空</option>
                    <option id="query_type_option_` + returnData.uuid + `_108" configid="` + configid + `" value="108">不为空</option>
                    <option id="query_type_option_` + returnData.uuid + `_123" configid="` + configid + `" value="123">今天之前(天)</option>
                    <option id="query_type_option_` + returnData.uuid + `_124" configid="` + configid + `" value="124">今天之后(天)</option>
                    <option id="query_type_option_` + returnData.uuid + `_125" configid="` + configid + `" value="125">今天之前第(天)</option>
                    <option id="query_type_option_` + returnData.uuid + `_126" configid="` + configid + `" value="126">今天之后第(天)</option>
                    <option id="query_type_option_` + returnData.uuid + `_127" configid="` + configid + `" value="127">今天之前N天以前</option>
                    <option id="query_type_option_` + returnData.uuid + `_128" configid="` + configid + `" value="128">今天之后N天以后</option>
                    <option id="query_type_option_` + returnData.uuid + `_129" configid="` + configid + `" value="129">单一日期</option>
                    <option id="query_type_option_` + returnData.uuid + `_130" configid="` + configid + `" value="130">小于等于今天</option>
                    <option id="query_type_option_` + returnData.uuid + `_131" configid="` + configid + `" value="131">大于等于今天</option>
                    <option id="query_type_option_` + returnData.uuid + `_132" configid="` + configid + `" value="132">小于今天</option>
                    <option id="query_type_option_` + returnData.uuid + `_133" configid="` + configid + `" value="133">大于今天</option>
                    <option id="query_type_option_` + returnData.uuid + `_134" configid="` + configid + `" value="134">今天之前N天以后</option>
                `;
                if(fbAnd){
                    queryTypeSelectHtml = `
                        <option id="query_type_option_` + returnData.uuid + `_101" configid="` + configid + `" value="101">等于</option>
                    `;
                }
                $("#queryTypeSelect_" + returnData.uuid).html(queryTypeSelectHtml);
            }
            //---------------------值选择
            var queryValueHtml = ``;
            if (dataType == "1") {
                var disabledHtml = ``;
                if (fromValue.queryType == "107" || fromValue.queryType == "108") {
                    disabledHtml = `disabled`;
                }
                if (columnType == "int" || columnType == "double") {
                    queryValueHtml = `<input onChange="treegrid.queryValueChange('` + returnData.uuid + `','` + configid + `', this)"  type="number" ` + disabledHtml + ` id="queryValueSelect_` + returnData.uuid + `" configid="` + configid + `" uuid="` + returnData.uuid + `" name="queryValue" lay-filter="queryValueSelect_` + returnData.uuid + `" class="layui-input">`;
                } if (columnType == "datetime") {
                    queryValueHtml = `<input readonly type="text" ` + disabledHtml + ` id="queryValueSelect_` + returnData.uuid + `" configid="` + configid + `" uuid="` + returnData.uuid + `" name="queryValue" lay-filter="queryValueSelect_` + returnData.uuid + `" class="layui-input">`;
                } else {
                    queryValueHtml = `<input onChange="treegrid.queryValueChange('` + returnData.uuid + `','` + configid + `', this)"  type="text" ` + disabledHtml + ` id="queryValueSelect_` + returnData.uuid + `" configid="` + configid + `" uuid="` + returnData.uuid + `" name="queryValue" lay-filter="queryValueSelect_` + returnData.uuid + `" class="layui-input">`;
                }
            } else if (dataType == "2") {
                // queryValue_
                queryValueHtml = `
                     <select id="queryValueSelect_` + returnData.uuid + `" configid="` + configid + `" uuid="` + returnData.uuid + `" name="queryValue" lay-filter="queryValue_` + returnData.uuid + `">
                 `
                 if(returnData.qfd == "delFlag" || returnData.qfd == "del_flag"){
                    code = "sys_del_flag";
                 }
                var option = kaValue.getUrl("getDicDataByType");
                option.url = option.url + "/" + code;
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        var redata = re.data;
                        for (var j in redata) {
                            queryValueHtml = queryValueHtml +
                                `<option id="query_value_option_` + returnData.uuid + `_` + redata[j].dictValue +
                                `" code="` + code + `" dataType="` + dataType + `" columnType="` + columnType + `" value="` + redata[j].dictValue + `">` +
                                redata[j].dictLabel + `</option>\r\n`;
                        }
                    }
                }
                ka.ajax(option);
                queryValueHtml = queryValueHtml + `</select>`
            } else {
                var disabledHtml = ``;
                if (fromValue.queryType == "107" || fromValue.queryType == "108") {
                    disabledHtml = `disabled`;
                }
                queryValueHtml = `<input onChange="treegrid.queryValueChange('` + returnData.uuid + `','` + configid + `')" type="text" id="queryValueSelect_` + returnData.uuid + `" ` + disabledHtml + ` configid="` + configid + `" uuid="` + returnData.uuid + `" name="queryValue" lay-filter="queryValueSelect_` + returnData.uuid + `" class="layui-input">`;
            }
            $("#queryValue_" + returnData.uuid).html(queryValueHtml);
            if (dataType == "1") {
                if (columnType == "datetime") {
                    if (fromValue.queryType == "113") { //今天
                        var result = layui.util.toDateString(new Date().getTime(), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "114") { // 昨天
                        var result = layui.util.toDateString((new Date().getTime() - 24 * 60 * 60 * 1000), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "115") { // 明天
                        var result = layui.util.toDateString((new Date().getTime() + 24 * 60 * 60 * 1000), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "116") { //上周
                        var result = layui.util.toDateString((new Date().getTime() - 7 * 24 * 60 * 60 * 1000), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "117") { // 本周
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "118") { // 下周
                        var result = layui.util.toDateString((new Date().getTime() + 7 * 24 * 60 * 60 * 1000), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "119") { // 上个月
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "120") { // 本月
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "121") { // 下个月
                        var result = layui.util.toDateString((new Date().getTime() - 24 * 60 * 60 * 1000), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "122") { // 月
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = "";
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        layui.laydate.render({
                            elem: '#queryValueSelect_' + returnData.uuid,
                            type: 'month',
                            done: function (value, date, endDate) {
                                var uuid = $("#" + this.id).attr("uuid");
                                var fromValue = ka_grid_QueryValue.get(uuid);
                                fromValue.queryValue = value;
                                ka_grid_QueryValue.set(uuid, fromValue);
                            }
                        });
                    } else if (fromValue.queryType == "123") { // 今天之前(天)
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "124") { // 今天之后(天)
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "125") { // 今天之前第(天)
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "126") { // 今天之后第(天)
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "127") { // 今天之前N天以前
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "128") { // 今天之后N天以后
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else if (fromValue.queryType == "129") { // 单一日期
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = "";
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        layui.laydate.render({
                            elem: '#queryValueSelect_' + returnData.uuid,
                            type: 'date',
                            done: function (value, date, endDate) {
                                var uuid = $("#" + this.id).attr("uuid");
                                var fromValue = ka_grid_QueryValue.get(uuid);
                                fromValue.queryValue = value;
                                ka_grid_QueryValue.set(uuid, fromValue);
                            }
                        });
                    } else if (fromValue.queryType == "130") { // 小于等于今天
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "131") { // 大于等于今天
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "132") { // 小于今天
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        $('#queryValueSelect_' + returnData.uuid).attr("disabled", "true");
                    } else if (fromValue.queryType == "133") { // 大于今天
                        var result = layui.util.toDateString((new Date().getTime()), 'yyyy-MM-dd HH:mm:ss');
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = result;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                    } else if (fromValue.queryType == "134") { // 今天之前N天以后
                        $('#queryValueSelect_' + returnData.uuid).attr("type", "number");
                        $('#queryValueSelect_' + returnData.uuid).removeAttr("readonly");
                    } else {
                        var fromValue = ka_grid_QueryValue.get(returnData.uuid);
                        fromValue.queryValue = fromValue.queryValue;
                        ka_grid_QueryValue.set(returnData.uuid, fromValue);
                        layui.laydate.render({
                            elem: '#queryValueSelect_' + returnData.uuid,
                            type: 'datetime',
                            done: function (value, date, endDate) {
                                var uuid = $("#" + this.id).attr("uuid");
                                var fromValue = ka_grid_QueryValue.get(uuid);
                                fromValue.queryValue = value;
                                ka_grid_QueryValue.set(uuid, fromValue);
                            }
                        });
                    }
                }
            } else if (dataType == "2") {
                layui.form.on('select(queryValue_' + returnData.uuid + ')', function (data) {
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值z
                    var uuid = $(elem).attr("uuid");
                    var fromValue = ka_grid_QueryValue.get(uuid);
                    fromValue.queryValue = value;
                    ka_grid_QueryValue.set(uuid, fromValue);
                });
            }
            //渲染
            layui.form.render();
            if (layerFormId != undefined && layerFormId != "") {
                layui.form.val(layerFormId, fromValue);
            }
        }
    },
    convertData: function (value, field) { // 转换数据 dt:数据类型,value:值,typeMap:参数
        if (value != undefined && value != "") {
            var dt = cdMap.get(field);
            var returnValue = "";
            var dataJsonStr = sessionStorage.getItem(dt + "_" + value);
            if (dataJsonStr != undefined && dataJsonStr != null && dataJsonStr != "") {
                var dataJson = JSON.parse(dataJsonStr);
                var dts = dt.split("_");
                returnValue = dataJson[dts[1]];
            } else {
                var dts = dt.split("_");
                if (dts[0] == "user") {
                    var option = kaValue.getUrl("getUserById");
                    option.url = option.url + "/" + value;
                    option.async = false;
                    option.success = function (re) {
                        if (re.code == 200) { //user_nickName
                            var data = re.data;
                            sessionStorage.setItem(dt + "_" + value, JSON.stringify(re.data));
                            returnValue = data[dts[1]];
                        }
                    }
                    ka.ajax(option);
                }
            }
            return returnValue;
        } else {
            return "";
        }
    },
    convertData2: function (code, dictValue) {
        var returnValue = "";
        var dataJsonStr = sessionStorage.getItem(code);
        if (dataJsonStr != undefined && dataJsonStr != null && dataJsonStr != "") {
            var dataJson = JSON.parse(dataJsonStr);
            for (var i in dataJson) {
                if (dataJson[i].dictValue == dictValue) {
                    returnValue = dataJson[i].dictLabel;
                    break;
                }
            }
        } else {
            var option = kaValue.getUrl("getColumnDicValue");
            option.url = option.url + "/" + code + "/" + dictValue;
            option.async = false;
            option.success = function (re) {
                if (re.code == 200) { //user_nickName
                    var dataJson = re.data;
                    sessionStorage.setItem(code, JSON.stringify(dataJson));
                    for (var i in dataJson) {
                        if (dataJson[i].dictValue == dictValue) {
                            returnValue = dataJson[i].dictLabel;
                            break;
                        }
                    }
                }
            }
            ka.ajax(option);
        }
        return returnValue;
    },
    convertWidth: function (field) { // 转换宽度 找系统宽度
        var width = 0;
        var dt = cdMap.get(field);
        var dts = dt.split("_");
        if (dts[0] == "user") {
            width = 160;
        }
        return width;
    },
    dropdownOpen: function (that) {
        var id = $(that).attr("id");
        var value = kaOptionButtonMaps.get(id);
        // 渲染
        var options = {
            elem: '#' + id, // 绑定元素选择器
            data: value,
            click: function (obj, othis) {
                obj.cb(obj.data);
            }
        };
        layui.dropdown.render(options);
        layui.dropdown.reload(id, options)
        layui.dropdown.open(id)
    }
}